package com.hhit.bigscreenbackmanage.service.impl.aqgl;

import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.util.IdUtil;
import cn.hutool.core.util.StrUtil;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hhit.bigscreenbackmanage.dao.aqgl.AqglMrboDao;
import com.hhit.bigscreenbackmanage.dao.aqgl.AqglRbDao;
import com.hhit.bigscreenbackmanage.entity.aqgl.TAqglMrbo;
import com.hhit.bigscreenbackmanage.entity.aqgl.TAqglRb;
import com.hhit.bigscreenbackmanage.service.aqgl.AqglMrboService;
import com.hhit.bigscreenbackmanage.service.aqgl.AqglRbService;
import com.hhit.bigscreenbackmanage.util.DateUtils;
import com.hhit.bigscreenbackmanage.util.Utils;
import com.hhit.bigscreenbackmanage.vo.aqgl.AqglSearchVo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * @ClassName AqglMrboServiceImpl
 * @Description
 * @Author qianchengcheng
 * @Date 2021/7/23
 */
@Service
public class AqglMrboServiceImpl implements AqglMrboService {

    private static Logger log = LoggerFactory.getLogger(AqglMrboServiceImpl.class);

    @Resource
    private AqglMrboDao aqglMrboDao;

    @Override
    public PageInfo geTAqglMrboPageInfo(AqglSearchVo aqglSearchVo) throws Exception {
        log.info("AqglMrboServiceImpl.getAqglMrboPageInfo Call Begin,param[aqglFxCountSearchVo:{}]", aqglSearchVo);
        int pageNum = aqglSearchVo.getPageNum() == null ? 1 : aqglSearchVo.getPageNum().intValue();
        int pageSize = aqglSearchVo.getPageSize() == null ? 15 : aqglSearchVo.getPageSize().intValue();
        PageHelper.startPage(pageNum, pageSize);
        List<TAqglMrbo> tAqglMrboList = aqglMrboDao.geTAqglMrboPageInfo(aqglSearchVo);
        PageInfo<TAqglMrbo> pageInfo = new PageInfo<>(tAqglMrboList);
        return pageInfo;
    }

    @Override
    public int insertAqglMrbo(TAqglMrbo tAqglMrbo) throws Exception {
        log.info("AqglRbServiceImpl.insertAqglMrbo Call Begin,param[tAqglMrbo:{}]",tAqglMrbo);
        tAqglMrbo.setId(IdUtil.fastSimpleUUID().toUpperCase());
        AqglSearchVo aqglSearchVo = new AqglSearchVo();
        aqglSearchVo.setDatetime(tAqglMrbo.getDatetime());
        List<TAqglMrbo> tAqglMrboList = aqglMrboDao.geTAqglMrboPageInfo(aqglSearchVo);
        int res = 0;
        if (!tAqglMrboList.isEmpty()){
            res = aqglMrboDao.updateAqglMrbo(tAqglMrbo);
        }else {
            res = aqglMrboDao.insertAqglMrbo(tAqglMrbo);
        }
        return res;
    }

    @Override
    public int updateAqglMrbo(TAqglMrbo tAqglMrbo) throws Exception {
        log.info("AqglRbServiceImpl.updateAqglMrbo Call Begin,param[tAqglMrbo:{}]",tAqglMrbo);
        int res = aqglMrboDao.updateAqglMrbo(tAqglMrbo);
        return res;
    }

    @Override
    public int deleteAqglMrbo(String datetime) throws Exception {
        log.info("AqglRbServiceImpl.deleteAqglMrbo Call Begin,param[datetime:{}]",datetime);
        int res = aqglMrboDao.deleteAqglMrbo(datetime);
        return res;
    }

}
